package sender;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Random;

public class DemoDto {
    private String time;
    private String name;
    private Integer byteSize;

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public Integer getByteSize() {
        return byteSize;
    }

    public void setByteSize(Integer byteSize) {
        this.byteSize = byteSize;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static DemoDto generateDemoDto(Integer size) {
        DemoDto demoDto = new DemoDto();
        Random random = new Random();
        LocalDateTime maxTime = LocalDateTime.of(2030, 12, 31, 23, 59);
        Instant instant = maxTime.toInstant(ZoneOffset.of("+8"));
        long epochSecond = instant.getEpochSecond();
        long index = (long) (Math.random() * 128 * 3600) + epochSecond - 128 * 3600;
        Instant instant1 = Instant.ofEpochMilli(index * 1000);

        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant1, ZoneId.systemDefault());
        String format = localDateTime.format(DateTimeFormatter.ISO_DATE_TIME);
        demoDto.setTime(format);
//        String substring = UUID.randomUUID().toString();

        //String substring1 = substring.substring(0, 5);
        String substring1 = "hello";
        demoDto.setName(substring1);

        int length = substring1.getBytes().length + format.getBytes().length;
        if (length < size) {
//            String s = generateText(size - length);
            demoDto.setByteSize(1);
        }
        return demoDto;
    }


    private static String generateText(Integer size) {
        StringBuilder stringBuilder = new StringBuilder();
        int bound = 'z' - 'A';
        for (int i = 0; i < size; i++) {
            Random random = new Random();
            int i1 = random.nextInt(bound);
            stringBuilder.append((char) ('A' + i1));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println("xEh`Gun[cZC`]vmi]iqdILFIFKAWoPH\\`jToHbVjfBHbTPlqAghVjLlaV[ZfKXoaOUgndn\\QeSpVBekmYuHUQAWAM[bw`EtsTFpN".getBytes().length);
        char s = 'A';
//        for (char i = s; i <= 'z'; i++) {
//            System.out.println(Character.valueOf(i));
//        }
//        String s1 = generateText(100);
//        System.out.println(s1);
        DemoDto demoDto = generateDemoDto(100);
        System.out.println(demoDto);

    }
}
